<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Architecture - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.tool.framework.architecture.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.tool.framework.architecture.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.tool.framework.clitool.html">Using the CLI Tool</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.tool.framework.html">Zend_Tool_Framework</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.tool.framework.writing-providers.html">Creating Providers to use with Zend_Tool_Framework</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.tool.framework.architecture" class="section"><div class="info"><h1 class="title">Architecture</h1></div>
    

    <div class="section" id="zend.tool.framework.architecture.registry"><div class="info"><h1 class="title">Registry</h1></div>
        

        <p class="para">
            Because providers and manifests may come from anywhere in the
            <span class="property">include_path</span>, a registry is provided to simplify access
            to the various pieces of the toolchain. This registry is injected
            into registry-aware components, which may then pull dependencies
            from them as necessary. Most dependencies registered with the
            registry will be sub-component-specific repositories.
        </p>

        <p class="para">
            The interface for the registry consists of the following definition:
        </p>

        <pre class="programlisting brush: php">
interface Zend_Tool_Framework_Registry_Interface
{
    public function setClient(Zend_Tool_Framework_Client_Abstract $client);
    public function getClient();
    public function setLoader(Zend_Tool_Framework_Loader_Abstract $loader);
    public function getLoader();
    public function setActionRepository(
        Zend_Tool_Framework_Action_Repository $actionRepository
    );
    public function getActionRepository();
    public function setProviderRepository(
        Zend_Tool_Framework_Provider_Repository $providerRepository
    );
    public function getProviderRepository();
    public function setManifestRepository(
        Zend_Tool_Framework_Manifest_Repository $manifestRepository
    );
    public function getManifestRepository();
    public function setRequest(Zend_Tool_Framework_Client_Request $request);
    public function getRequest();
    public function setResponse(Zend_Tool_Framework_Client_Response $response);
    public function getResponse();
}
</pre>


        <p class="para">
            The various objects the registry manages will be discussed in their
            appropriate sections.
        </p>

        <p class="para">
            Classes that should be registry-aware should implement
            <span class="classname">Zend_Tool_Framework_Registry_EnabledInterface</span>. This
            interface merely allows initialization of the registry in the target
            class.
        </p>

        <pre class="programlisting brush: php">
interface Zend_Tool_Framework_Registry_EnabledInterface
{
    public function setRegistry(
        Zend_Tool_Framework_Registry_Interface $registry
    );
}
</pre>

    </div>

    <div class="section" id="zend.tool.framework.architecture.providers"><div class="info"><h1 class="title">Providers</h1></div>
        

        <p class="para">
            <span class="classname">Zend_Tool_Framework_Provider</span> represents the functional
            or &quot;capability&quot; aspect of the framework. Fundamentally,
            <span class="classname">Zend_Tool_Framework_Provider</span> will provide the
            interfaces necessary to produce &quot;providers&quot;, or bits of tooling
            functionality that can be called and used inside the
            <span class="classname">Zend_Tool_Framework</span> toolchain. The simplistic nature of
            implementing this provider interface allows the developer a
            &quot;one-stop-shop&quot; of adding functionality or capabilities to
            <span class="classname">Zend_Tool_Framework</span>.
        </p>

        <p class="para">
            The provider interface is an empty interface and enforces no methods
            (this is the Marker Interface pattern):
        </p>

        <pre class="programlisting brush: php">
interface Zend_Tool_Framework_Provider_Interface
{}
</pre>


        <p class="para">
            Or, if you wish, you can implement the base (or abstract) Provider
            which will give you access to the
            <span class="classname">Zend_Tool_Framework_Registry</span>:
        </p>

        <pre class="programlisting brush: php">
abstract class Zend_Tool_Framework_Provider_Abstract
    implements Zend_Tool_Framework_Provider_Interface,
               Zend_Tool_Registry_EnabledInterface
{
    protected $_registry;
    public function setRegistry(
        Zend_Tool_Framework_Registry_Interface $registry
    );
}
</pre>

    </div>

    <div class="section" id="zend.tool.framework.architecture.loaders"><div class="info"><h1 class="title">Loaders</h1></div>
        

        <p class="para">
            The purpose of a Loader is to find Providers and Manifest files that
            contain classes which implement either
            <span class="classname">Zend_Tool_Framework_Provider_Interface</span> or
            <span class="classname">Zend_Tool_Framework_Manifest_Interface</span>. Once these files are
            found by a loader, providers are loaded into the Provider Repository and
            manifest metadata is loaded into the Manifest Repository.
        </p>

        <p class="para">
            To implement a loader, one must extend the following abstract class:
        </p>

        <pre class="programlisting brush: php">
abstract class Zend_Tool_Framework_Loader_Abstract
{

    abstract protected function _getFiles();

    public function load()
    {
        /** ... */
    }
}
</pre>


        <p class="para">
            The  <span class="methodname">_getFiles()</span> method should return an array of files
            (absolute paths). The built-in loader supplied with Zend Framework is called the
            IncludePath loader. By default, the Tooling framework will use an
            include_path based loader to find files that might include Providers
            or Manifest Metadata objects.
            <span class="classname">Zend_Tool_Framework_Loader_IncludePathLoader</span>, without
            any other options, will search for files inside the include path
            that end in <var class="filename">Mainfest.php</var>, <var class="filename">Tool.php</var> or
            <var class="filename">Provider.php</var>. Once found, they will be tested (by the
             <span class="methodname">load()</span> method of the
            <span class="classname">Zend_Tool_Framework_Loader_Abstract</span>) to determine if
            they implement any of the supported interfaces. If they do, an
            instance of the found class is instantiated, and it is appended to
            the proper repository.
        </p>

        <pre class="programlisting brush: php">
class Zend_Tool_Framework_Loader_IncludePathLoader
    extends Zend_Tool_Framework_Loader_Abstract
{

    protected $_filterDenyDirectoryPattern = &#039;.*(/|\\\\).svn&#039;;
    protected $_filterAcceptFilePattern = &#039;.*(?:Manifest|Provider)\.php$&#039;;

    protected function _getFiles()
    {
        /** ... */
    }
}
</pre>


        <p class="para">
            As you can see, the IncludePath loader will search all include_paths
            for the files that match the <var class="varname">$_filterAcceptFilePattern</var>
            and <em class="emphasis">not</em> match the <var class="varname">$_filterDenyDirectoryPattern</var>.
        </p>
    </div>

    <div class="section" id="zend.tool.framework.architecture.manifests"><div class="info"><h1 class="title">Manifests</h1></div>
        

        <p class="para">
            In short, the Manifest shall contain specific or arbitrary metadata
            that is useful to any provider or client, as well as be responsible
            for loading any additional providers into the provider repository.
        </p>

        <p class="para">
            To introduce metadata into the manifest repository, all one must do
            is implement the empty <span class="classname">Zend_Tool_Framework_Manifest_Interface</span>,
            and provide a  <span class="methodname">getMetadata()</span> method which shall return an array
            of objects that implement <span class="classname">Zend_Tool_Framework_Manifest_Metadata</span>.
        </p>

        <pre class="programlisting brush: php">
interface Zend_Tool_Framework_Manifest_Interface
{
    public function getMetadata();
}
</pre>


        <p class="para">
            Metadata objects are loaded (by a loader defined below) into the
            Manifest Repository (<span class="classname">Zend_Tool_Framework_Manifest_Repository</span>).
            Manifests will be processed after all Providers have been found to be
            loaded into the provider repository. This shall allow Manifests to
            create Metadata objects based on what is currently inside the
            provider repository.
        </p>

        <p class="para">
            There are a few different metadata classes that can be used to
            describe metadata. The
            <span class="classname">Zend_Tool_Framework_Manifest_Metadata</span> is the base
            metadata object. As you can see by the following code
            snippet, the base metadata class is fairly lightweight and
            abstract in nature:
        </p>

        <pre class="programlisting brush: php">
class Zend_Tool_Framework_Metadata_Basic
{

    protected $_type        = &#039;Global&#039;;
    protected $_name        = null;
    protected $_value       = null;
    protected $_reference   = null;

    public function getType();
    public function getName();
    public function getValue();
    public function getReference();
    /** ... */
}
</pre>


        <p class="para">
            There are other built in metadata classes as well for describing
            more specialized metadata: <span class="classname">ActionMetadata</span> and
            <span class="classname">ProviderMetadata</span>. These classes will help you describe
            in more detail metadata that is specific to either actions or
            providers, and the reference is expected to be a reference to an
            action or a provider respectively. These classes are described in
            the following code snippet.
        </p>

        <pre class="programlisting brush: php">
class Zend_Tool_Framework_Manifest_ActionMetadata
    extends Zend_Tool_Framework_Manifest_Metadata
{

    protected $_type = &#039;Action&#039;;
    protected $_actionName = null;

    public function getActionName();
    /** ... */
}

class Zend_Tool_Framework_Manifest_ProviderMetadata
    extends Zend_Tool_Framework_Manifest_Metadata
{

    protected $_type = &#039;Provider&#039;;
    protected $_providerName  = null;
    protected $_actionName    = null;
    protected $_specialtyName = null;

    public function getProviderName();
    public function getActionName();
    public function getSpecialtyName();
    /** ... */
}
</pre>


        <p class="para">
            &#039;Type&#039; in these classes is used to describe the type of metadata the
            object is responsible for. In the cases of the
            <span class="classname">ActionMetadata</span>, the type would be &#039;Action&#039;, and
            conversely in the case of the <span class="classname">ProviderMetadata</span> the type
            is &#039;Provider&#039;. These metadata types will also include additional
            structured information about both the &quot;thing&quot; they are describing as
            well as the object (the  <span class="methodname">getReference()</span>) they are
            referencing with this new metadata.
        </p>

        <p class="para">
            In order to create your own metadata type, all one must do is extend
            the base <span class="classname">Zend_Tool_Framework_Manifest_Metadata</span> class
            and return these new metadata objects via a local Manifest
            class or object. These user based classes will live in the Manifest
            Repository
        </p>

        <p class="para">
            Once these metadata objects are in the repository, there are then two
            different methods that can be used in order to search for them in
            the repository.
        </p>

        <pre class="programlisting brush: php">
class Zend_Tool_Framework_Manifest_Repository
{
    /**
     * To use this method to search, $searchProperties should contain the names
     * and values of the key/value pairs you would like to match within the
     * manifest.
     *
     * For Example:
     *     $manifestRepository-&gt;findMetadatas(array(
     *         &#039;action&#039; =&gt; &#039;Foo&#039;,
     *         &#039;name&#039;   =&gt; &#039;cliActionName&#039;
     *         ));
     *
     * Will find any metadata objects that have a key with name &#039;action&#039; value
     * of &#039;Foo&#039;, AND a key named &#039;name&#039; value of &#039;cliActionName&#039;
     *
     * Note: to either exclude or include name/value pairs that exist in the
     * search criteria but do not appear in the object, pass a bool value to
     * $includeNonExistentProperties
     */
    public function findMetadatas(Array $searchProperties = array(),
                                  $includeNonExistentProperties = true);

    /**
     * The following will return exactly one of the matching search criteria,
     * regardless of how many have been returned. First one in the manifest is
     * what will be returned.
     */
    public function findMetadata(Array $searchProperties = array(),
                                 $includeNonExistentProperties = true)
    {
        $metadatas = $this-&gt;getMetadatas($searchProperties,
                                         $includeNonExistentProperties);
        return array_shift($metadatas);
    }
}
</pre>


        <p class="para">
            Looking at the search methods above, the signatures allow for
            extremely flexible searching. In order to find a metadata object,
            simply pass in an array of matching constraints via an array. If
            the data is accessible through the Property accessor (the
             <span class="methodname">getSomething()</span> methods implemented on the metadata
            object), then it will be passed back to the user as a &quot;found&quot;
            metadata object.
        </p>
    </div>

    <div class="section" id="zend.tool.framework.architecture.clients"><div class="info"><h1 class="title">Clients</h1></div>
        

        <p class="para">
            Clients are the interface which bridges a user or external tool into
            the <span class="classname">Zend_Tool_Framework</span> system. Clients can come in all
            shapes and sizes: <acronym class="acronym">RPC</acronym> endpoints, Command Line Interface, or
            even a web interface. <span class="classname">Zend_Tool</span> has implemented the command
            line interface as the default interface for interacting with
            the <span class="classname">Zend_Tool_Framework</span> system.
        </p>

        <p class="para">
            To implement a client, one would need to extend the following
            abstract class:
        </p>

        <pre class="programlisting brush: php">
abstract class Zend_Tool_Framework_Client_Abstract
{
    /**
     * This method should be implemented by the client implementation to
     * construct and set custom loaders, request and response objects.
     *
     * (not required, but suggested)
     */
    protected function _preInit();

    /**
     * This method should be implemented by the client implementation to parse
     * out and set up the request objects action, provider and parameter
     * information.
     */
    abstract protected function _preDispatch();

    /**
     * This method should be implemented by the client implementation to take
     * the output of the response object and return it (in an client specific
     * way) back to the Tooling Client.
     *
     * (not required, but suggested)
     */
    abstract protected function _postDispatch();
}
</pre>


        <p class="para">
            As you can see, there 1 method is required to fulfill the needs of a
            client (two others suggested), the initialization, prehandling and post handling. For a
            more in depth study of how the command line client works, please see
            the <a href="http://framework.zend.com/svn/framework/standard/branches/release-1.8/library/Zend/Tool/Framework/Client/Console.php" class="link external">&raquo; source
                code</a>.
        </p>
    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.tool.framework.clitool.html">Using the CLI Tool</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.tool.framework.html">Zend_Tool_Framework</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.tool.framework.writing-providers.html">Creating Providers to use with Zend_Tool_Framework</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="reference.html">Refer&ecirc;ncia do Zend Framework</a></li>
  <li class="header up"><a href="zend.tool.framework.html">Zend_Tool_Framework</a></li>
  <li><a href="zend.tool.framework.introduction.html">Introduction</a></li>
  <li><a href="zend.tool.framework.clitool.html">Using the CLI Tool</a></li>
  <li class="active"><a href="zend.tool.framework.architecture.html">Architecture</a></li>
  <li><a href="zend.tool.framework.writing-providers.html">Creating Providers to use with Zend_Tool_Framework</a></li>
  <li><a href="zend.tool.framework.system-providers.html">Shipped System Providers</a></li>
  <li><a href="zend.tool.framework.extending.html">Extending and Configuring Zend_Tool_Framework</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>